package utils

import "MetroBuilderGameJam/gameEngine/geom"

type ItemFigure interface {
	GetCollider() geom.Collider
	GetItem() any
}

func NewFigure(item any, collider geom.Collider) *Figure {
	return &Figure{
		collider: collider,
		item:     item,
	}
}

type Figure struct {
	collider geom.Collider
	item     any
}

var _ ItemFigure = &Figure{}

func NoFigure() *Figure {
	return &Figure{
		collider: &geom.ColliderPoint{},
	}
}

func (f *Figure) GetCollider() geom.Collider {
	return f.collider
}

func (f *Figure) GetItem() any {
	return f.item
}

func ItemAs[T any](item any) *T {
	if s, ok := item.(*T); ok {
		return s
	}
	return nil
}

func FigureItemAs[T any](figure ItemFigure) *T {
	if figure == nil {
		return nil
	}
	return ItemAs[T](figure.GetItem())
}
